#include<iostream>
using namespace std;
const int N = 1e3 + 10;
int a[N];
int n;
int main()
{
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++)cin >> a[i];
	for (int i = 2; i <= n - 1; i++) {
		if ((a[i] > a[i - 1] && a[i] > a[i + 1]) || 
			(a[i] < a[i - 1] && a[i] < a[i + 1]))ans++;
	}
	cout << ans << endl;
	return 0;
}